package com.hntky.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hntky.common.Result;
import com.hntky.entity.Sickroom;
import com.hntky.service.SickroomService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 周宇轩
 * @date 2023/5/14 16:12
 */
@RestController
@RequestMapping("/room")
public class SickroomController {

    @Resource
    private SickroomService service;

    @GetMapping("/")
    public Result index(){
        return Result.success(service.list());
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param nname
     * @return
     */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String nname) {
        return Result.success(service.findPage(new Page<>(pageNum, pageSize), nname));
    }

    /**
     * 新增和修改
     * @param sickroom
     * @return
     */
    @PostMapping("/add")
    public Result addAndUpdate(@RequestBody Sickroom sickroom) {
        return Result.success(service.saveOrUpdate(sickroom));
    }

    /**
     * 查询护士
     * @param sid
     * @return
     */
    @GetMapping("/nurses/{sid}")
    public Result findNurses(@PathVariable Integer sid) {
        return Result.success(service.findNurses(sid));
    }

    /**
     * 根据id删除
     * @param sid
     * @return
     */
    @GetMapping("/{sid}")
    public Result del(@PathVariable Integer sid) {
        return Result.success(service.removeById(sid));
    }

    @PostMapping("/del/batch")
    public Result delBatch(@RequestBody List<Integer> sids) {
        return Result.success(service.removeBatchByIds(sids));
    }
}


